package com.itguigu.ioc_04;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class JavaBean {

    /**
     * 使用xml方式对bean的属性进行赋值
     * <bean id="javaBean" class="com.atguigu.ioc_04.JavaBean">
     * <property name="name" value="zhangsan"/>
     * ....
     * </bean>
     */
    //方式一：直接在类中赋值
    private String name = "zhangsan";

    //方式二：使用Value注解
    @Value("18")
    private int age;

    //方式三：使用配置文件信息
    @Value("${jdbc.password}")
    private String password;


    @Value("${jdbc.username:admin}")// :默认值
    private String username;

    @Override
    public String toString() {
        return "JavaBean{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", password='" + password + '\'' +
                ", username='" + username + '\'' +
                '}';
    }
}
